<template>
    <div class="page add-member">        
        <div class="weui-cells weui-cells_radio select-role">
            <label class="weui-cell weui-check__label" :for="'x'+taskItem.id" v-for="(index, taskItem) in taskList" @click="setTask(taskItem.id,taskItem.name)">
                <div class="weui-cell__bd regular">
                    <span class="deleted" v-if="taskItem.status == 2">已删除</span>
                    <h2 class="regular_name">{{taskItem.name}}</h2>
                </div>
                <div class="weui-cell__ft">
                    <input type="radio" class="weui-check" name="radio1" :id="'x'+taskItem.id" v-bind:checked="selectedIdentityId == taskItem.id">
                    <span class="weui-icon-checked"></span>
                </div>
            </label>
        </div>
    </div>   
</template>

<script>
    /**
     *  引入工具类库 或 Native API
     *  example : import widget from 'gapi/widget'
     */
    import $ from 'zepto'
    import widget from 'gapi/widget.js'
    import cache from 'gapi/cache'
    import * as util from 'js/util.js'
    import userCenterApi from 'clientApi/userCenterApi'
    import clientInfo from 'gapi/clientInfo'
    import commonPage from 'clientApi/commonPage.js'
    /**
     *  引入组件 以及 组件接口(Action)
     *  example : import Somecomponents from 'components/Somecomponents/Somecomponents'
     */

    /**
     *  组件实例对象
     */
    export default {
        components: {

        },
        data: function(){
            return{
                types: [],
                userId: '',
                selectedTypeId : '',
                roleType: {
                    roleid: '',
                    rolename: ''
                },
                isClick: false,
                selectedIdentityId : '',
                isDeleted: false,//考勤规则是否已经删除
                taskList:[],
            }
        },
        vuex: {
            getters: {

            },
            actions: {

            }
        },
        methods: {
            /**
             * 初始化
             * @method init
             * @public
             * @return {Null} void
             */
            init (){
              this.projectId = util.getUrddataString('pId')
              this.teamId = util.getUrddataString('tId')
              cache.getMemoryCache('selectTask', (data) => {
                   if(data){
                       this.selectedIdentityId = data
                   } 
               })
              //获取角色列表
              this.getTaskList()
            },
            // 获取考勤任务列表
            getTaskList (){
                commonPage.loadPageStatus('loading')
                util.ajax({
                    url: '/attendance/attendance_task_names',
                    data: {
                        team_id: this.teamId,
                        project_id: this.projectId,
                        page_size: 10000
                    },
                    success: (res) => {
                        console.log("考勤任务列表"+JSON.stringify(res))
                        if(res.errno == 0){                            
                            // 请求数据成功
                            this.taskList = res.data
                            // this.taskList.forEach((obj) => {
                            //     if(obj.status == 2){
                            //         obj.name = obj.name + '(已删除)'
                            //     }else{
                            //         obj.name = obj.name
                            //     }
                            // })
                            
                        }else{
                            widget.toast('服务器异常')
                        }
                        
                        commonPage.loadPageStatus('loadSuccess')
                    },
                    error: (xhr, error) => {
                        widget.toast('服务器异常')
                        commonPage.loadPageStatus('loadSuccess')
                    },
                    noNetwork: () => {
                        // 无网络的回调
                        widget.toast('网络连接失败，请检查网络')
                    }
                })
            },
            //选择考勤规则
            setTask (taskId,taskName){
                if(this.isClick){
                    return
                }
                this.isClick = true
                let taskList = {
                    id: taskId,
                    name: taskName 
                }
                cache.getMemoryCache('webViewID',function(data){
                    if(data){
                        setTimeout(() =>{ 
                            commonPage.goBack(1,{'key':'selectTask','value':taskList},data.webViewID)},200)
                    }
                })
                
            }
        },
        created(){

            this.init();

        },
        ready(){
            // cache.getMemoryCache('projectTypeId', (data) => {
            //         if(data){
            //             this.selectedTypeId = data
            //         }
            // })
            // cache.getMemoryCache('identityId', (data) => {
            //         if(data && data.val){
            //             this.selectedIdentityId = data.val
            //         }
            // })

            // userCenterApi.getUserInfo( data => {//userId
            //     this.userId = data.userId
            // })

        }

    }


</script>

<!-- CSS 样式 -->
<style src="../../node_modules/weui/dist/style/weui.css"></style>
<style src="../../static/css/common.css"></style>
<style src="../../static/css/project.css"></style>
<style>
    .weui-cells_radio .weui-check:checked + .weui-icon-checked:before {
        display: block;
        content: "";
        width: 18px;
        height: 18px;
        background-image: url(../../static/imgs/single_selected.png);
        background-size: 18px 18px;
        overflow: hidden;
    }
    .deleted{
        width: 44px;
        height: 20px;
        opacity: 0.6;
        background: #949AA8;
        font-size: 12px;
        color: #FFFFFF;
        letter-spacing: 0;
        padding: 2px;
        margin-right: 6px;
        border: solid 1px #949AA8;
        border-radius: 2px;
    }
    .regular_name{
        display: inline-block;
        height: 22px;
        position: relative;
        top: 2px;
    }
</style>
